/**
*    Copyright (C) 2008  Chase Kernan 
*    chase.kernan@gmail.com
*
*    This program is free software: you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation, either version 3 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License
*    along with this program.  If not, see <http://www.gnu.org/licenses/>.
* 
**/

package com.chasekernan.hxnova.client;

/*
//import all - er well, not all, but at least the classes that, when imported,
//will import all of the classes.
import com.chasekernan.hxnova.core.SpaceObject;
import com.chasekernan.hxnova.core.components.ComponentSet;
import com.chasekernan.hxnova.core.battles.BattlePlan;
import com.chasekernan.hxnova.core.battles.BattleRecord;
import com.chasekernan.hxnova.core.dataholders.Global;
import com.chasekernan.hxnova.core.dataholders.Map;
import com.chasekernan.hxnova.core.designs.HullDesign;
import com.chasekernan.hxnova.core.fleets.Fleet;
import com.chasekernan.hxnova.core.fleets.Salvage;
import com.chasekernan.hxnova.core.minerals.MineralSet;
import com.chasekernan.hxnova.core.players.Player;
import com.chasekernan.hxnova.core.players.PlayerTurnFile;
import com.chasekernan.hxnova.core.players.TurnOrders;
import com.chasekernan.hxnova.core.races.Race;
import com.chasekernan.hxnova.core.races.LRTSet;
import com.chasekernan.hxnova.core.races.PRTSet;
import com.chasekernan.hxnova.core.stars.Concentrations;
import com.chasekernan.hxnova.core.stars.MapCreator;
import com.chasekernan.hxnova.core.stars.ProductionQueue;
import com.chasekernan.hxnova.core.stars.Star;
import com.chasekernan.hxnova.utils.IntVector;
//import com.chasekernan.hxnova.utils.Rectangle;
import com.chasekernan.hxnova.utils.Utils;
import com.chasekernan.hxnova.utils.VarLoader;
import com.chasekernan.hxnova.utils.Vector;
import com.chasekernan.hxnova.utils.XmlBuilder;
*/

#if flash9
import com.chasekernan.hxnova.client.mapviewer.MapViewer;
import com.chasekernan.hxnova.client.mapviewer.MapOptions;
import com.chasekernan.hxnova.client.mapviewer.IMapObject;
import com.chasekernan.hxnova.core.components.StarScanner;
import com.chasekernan.hxnova.core.components.ComponentSet;
import com.chasekernan.hxnova.client.mapviewer.StarObject;
import com.chasekernan.hxnova.core.dataholders.Global;
import com.chasekernan.hxnova.core.races.Race;
import com.chasekernan.hxnova.server.Game;
import flash.geom.Rectangle;
import flash.events.Event;
import com.chasekernan.hxnova.core.stars.Star;
import com.chasekernan.hxnova.core.fleets.Fleet;
import com.chasekernan.hxnova.utils.IntVector;
import com.chasekernan.hxnova.utils.Vector;
import com.chasekernan.hxnova.utils.Translator;
import com.chasekernan.hxnova.client.mapviewer.FleetObject;

import com.chasekernan.hxnova.client.plugins.PluginManager;
import com.chasekernan.hxnova.client.ClientBase;
#end

class Main {
    
    #if neko
    public static function main() {
        SwhxBase.getInstance().run();
    }
    
    #elseif flash9
    public static function main() {
        ClientBase.getInstance().loadAswing(
            function() {
                Translator.init(
                    function() {
                        generateGame(
                            function() {
                                PluginManager.getInstance().loadPlugins();
                            }
                        );
                    }
                );
            }
        );
    }
    
    public static function generateGame(?onComplete : Void -> Void) {
        var connection  = ClientBase.getInstance().getConnection();
        
        haxe.Log.trace  = function(v : Dynamic, ?posInfos : haxe.PosInfos) {
            connection.SwhxBase.showMessage.call([posInfos.fileName, 
                                                  Std.string(v)]);
        };
        
        //introduce a scanner
        var scanner = new StarScanner("Viwer 50", 100, 50);
        ComponentSet.addComponent(scanner);
        
        var races = new Array<Race>();
        for (i in 0...6) {
            var race = new Race();
            race.name = "Race #" + i;
            races.push(race);
        }
        
        var g = new Game();
        g.name = "test";
        g.data = {races : races, 
                  map : { numStars : 300, type : MapType.Ring(1000, 500) }};
        
        Game.createNewGame(g);
        Global.player = Global.players.players[0];
        
        if (onComplete != null) onComplete();
    }
    #end
}
